using System;
using System.Collections.Generic;
using System.Text;
using CodePlex.Resourceful.Amazon.SimpleDB;
using System.IO;

namespace CodePlex.Resourceful.Examples
{
    public static class SimpleDBExample
    {

        public static void Run()
        {
            string aws = Environment.GetEnvironmentVariable("AWS");

            string accessKeyID = aws.Split(':')[0];
            string secretAccessKey = aws.Split(':')[1];


            string method = HttpMethod.Get;

            SimpleDBClient client = new SimpleDBClient(accessKeyID, secretAccessKey, false, method);
            client.Tracer.AddListener(Console.Out);

            string domain = "Domain" + Guid.NewGuid().ToString().Replace("-", "");

            client.CreateDomain(domain);
            client.ListDomains();

            client.PutAttributes(domain, "Item123",
                new NameValue("Color", "Blue"),
                new NameValue("Size", "Med"),
                new NameValue("Price", "0014.99"));
            client.GetAttributes(domain, "Item123");
            client.GetAttributes(domain, "Item123", "Color", "Price");

            client.PutAttributes(domain, "Item123", new NewNameValue("Color", "Green", true));
            client.GetAttributes(domain, "Item123");

            client.Select("select * from " + domain, null);

            client.DeleteAttributes(domain, "Item123", new NameOnly("Size"));
            client.GetAttributes(domain, "Item123");

            client.DeleteAttributes(domain, "Item123");
            client.GetAttributes(domain, "Item123");

            client.BatchPutAttributes(domain, Fn.Select(Fn.Range(25), delegate(int i)
            {
                return new ItemAndAttributes("Item" + i, new NameValue("Att1", "Value1"), new NameValue("Att2", "Value2"));
            }));

            client.DomainMetadata(domain);

            client.DeleteDomain(domain);
            client.ListDomains();
            
            
 
            

        }   







    }
}
